<template>
  <div class="mcontaner">
	<Banner></Banner>
    <div class="block"  v-loading="loading">
      <el-timeline v-if="blogs.length!=0">
        <el-timeline-item :timestamp="blog.created" placement="top" v-for="(blog,index) in blogs" :key="index">
          <el-card>
            <h4>
              <router-link :to="{name: 'BlogDetail', params: {blogId: blog.id}}">
                {{blog.title}}
              </router-link>
            </h4>
            <p>{{blog.description}}</p>
          </el-card>
        </el-timeline-item>

      </el-timeline>
	  <el-empty v-else description="还没有发表文章哦"></el-empty>
    </div> 
	<el-pagination class="mpage"
	               background
	               layout="prev, pager, next"
	               :current-page="currentPage"
	               :page-size="pageSize"
	               :total="total"
	               @current-change=page>
	</el-pagination>
  </div>
</template>

<script>
  import Banner from "../components/banner.vue"
  
  export default {
    name: "Blogs.vue",
    components: {Banner},
    data() {
      return {
		  loading:true,
        blogs: {},
        currentPage: 1,
        total: 0,
        pageSize: 5
      }
    },
    methods: {
      page(currentPage) {
        const _this = this
        _this.$axios.get("/blogs?currentPage=" + currentPage).then(res => {
          console.log(res)
		  _this.loading = false
          _this.blogs = res.data.data.records
          _this.currentPage = res.data.data.current
          _this.total = res.data.data.total
          _this.pageSize = res.data.data.size

        })
      }
    },
    created() {
      this.page(1)
    }
  }
</script>

<style scoped>

  .mpage {
    margin: 0 auto;
    text-align: center;
  }
  .block{
	  min-height: 300px;
  }

</style>